package br.com.napoleao.controlfin.core.business.bo;

import java.util.List;

import br.com.napoleao.controlfin.core.entity.ContaEntity;
import br.com.napoleao.controlfin.core.exception.BusinessException;

public class ContaBO {

	public void validarObjeto(ContaEntity conta) throws BusinessException{
		
		BusinessException exception = new BusinessException();
		
		if(conta.getNome() == null || conta.getNome().equals("")){
			exception.addMessage("Favor preencher o campo Nome");
		}
		if(conta.getSaldoInicial() == null){
			exception.addMessage("Favor preencher o campo Saldo Inicial");
		}
		
		if(exception.getMessages().size() > 0){
			throw exception;
		}
	}
	
	public Double somarSaldo(List<ContaEntity> contas){
		
		Double total = 0D;
		
		for (ContaEntity contaEntity : contas) {
			total += contaEntity.getSaldoInicial();
		}
		
		return total;
	}
}
